<?php



/*
function GetDataFromURL($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);    
		return $output;
}
*/


function MALRecentAnime($username) {
	global $SITE_MIDDLE;
	global $lang;
	$requesturl = "http://myanimelist.net/rss.php?type=rw&u=$username";
	$xml = GetDataFromURL($requesturl);
		$sxml = new SimpleXMLElement($xml);
	$i=0;
	$anime = "<table width='100%'>";
	foreach ($sxml->channel->item as $item){
		$i++;
		if ($i>10) break;
		$anime .= "<tr><td width='50%'>$item->title</td>";
		$anime .= "<td width='50%'>$item->description</td></tr>";
	}
	$anime.= "</table>";
	if ($i) $SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_malrecentanime"), $anime);	
}


function MALRecentManga($username) {
	global $SITE_MIDDLE;
	global $lang;
	$requesturl = "http://myanimelist.net/rss.php?type=rm&u=$username";
	$xml = GetDataFromURL($requesturl);
		$sxml = new SimpleXMLElement($xml);
	$i=0;
	$manga = "<table width='100%'>";
	foreach ($sxml->channel->item as $item){
		$i++;
		if ($i>10) break;
		$manga .= "<tr><td width='50%'>$item->title</td>";
		$manga .= "<td width='50%'>$item->description</td></tr>";
	}
	$manga.= "</table>";
	if ($i) $SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_malrecentmanga"), $manga);	
}


$query = "select * from `profileexternal` where `user`='$profile_id'";
$result = mysql_query($query);
if ($result) {
	$external = mysql_fetch_array($result);
	$query = "select * from `external` where `site`='myanimelist' and `userid`='$profile_id'";
	$result = mysql_query($query);
	if ($result) {
		$mal = mysql_fetch_array($result);
		$malname = $mal['username'];
		if ($external['mal'] == 1) MALRecentAnime($malname);
		if ($external['mal'] == 2) MALRecentManga($malname);
	}
}


?>
